<template>
  <div class="add">
    <div class="add-header">
      <span class="iconfont" @click="back">&#xe612;</span>
      <div class='title'>新增地址</div>
      <div class="right"></div>
    </div>
    <div class="add-con">
      <div class="add-info">
        <div class="add-name">
          <p class="add-person">收货人</p>
        </div>
        <input type="text" placeholder="收货人姓名" class="add-input" v-model="name">
      </div>
      <div class="add-info">
        <div class="add-name">
          <p class="add-person">手机号码</p>
        </div>
        <input type="text" placeholder="收货人的手机号码" class="add-input" v-model="iphone">
      </div>
      <div class="add-info">
        <div class="add-name">
          <p class="add-person">选择地区</p>
        </div>
        <input type="text" placeholder="请选择收货地址" class="add-input" v-model="zone">
      </div>
      <div class="add-info">
        <div class="add-name">
          <p class="add-person">详细地址</p>
        </div>
        <input type="text" placeholder="详细街道地址" class="add-input" v-model="detail">
      </div>
    </div>
    <div class="add-footer">
      <p class="add-save" @click='btnSave'>保存地址</p>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapMutations } from 'vuex'
import { Toast } from 'mint-ui'
export default {
  data() {
    return {
      name: '',
      iphone: '',
      zone: '',
      detail: ''
    }
  },
  methods: {
    back: function(){
      this.$router.go(-1)
    },
     // 保存地址信息
    btnSave: function(){
      // 判断输入是否为空
      if(this.name == '' || this.iphone == '' || this.zone == '' || this.detail == ''){
        Toast({
          message: '信息请填写完整',
          duration: 950
        });
      }else{
        var data = {
          name: this.name,
          iphone: this.iphone,
          zone: this.zone,
          detail: this.detail
        };
        this.$store.dispatch('setAddress', data);
        // 跳转到上一个页面
        this.$router.back();
      }
    }
  },

}
</script>

<style lang="less">
  .add{
    .add-header{
      position: fixed;
      top: 0;
      z-index: 2;
      background: white;
      width: 100%;
      height: 1.5rem;
      color: #777;
      border-bottom: 1px solid #eee;
      span{
        width: 10%;
        float: left;
        height: 1.5rem;
        line-height: 1.5rem;
        font-size: .8rem;
        text-align: center;
      }
      .title{
        width: 80%;
        float: left;
        line-height: 1.5rem;
        text-align: center;
        margin: 0 auto;
        font-size: .5rem;
      }
      .right{
        float: left;
        width: 10%;
        line-height: 1rem;
      }
    }
    .add-con{
      padding-top: 1.5rem;
      .add-info{
        width: 100%;
        height: 1.2rem;
        line-height: 1.2rem;
        background: white;
        border-bottom: 1px solid #eee;
        .add-name{
          width: 30%;
          float: left;
          .add-person{
            float: right;
            margin-right: .4rem;
            font-size: .4rem;
          }
        }
        .add-input{
          width: 60%;
          float: left;
          height: 1rem;
          margin-top: .1rem;
          font-size: .4rem;
        }
      }
    }
    .add-footer{
      position: fixed;
      bottom: 0;
      background: white;
      width: 100%;
      height: 1.2rem;
      .add-save{
        width: 90%;
        height: .8rem;
        margin: .2rem auto;
        border-radius: .4rem;
        background: #00ACFF;
        color: white;
        text-align: center;
        line-height: .8rem;
        font-size: .32rem;
      }
    }
  }
</style>
